﻿/**
 *	html/pem_data_alarm.js
 *
 *	(C) 2014 Yuanjj
 *
 * 	history:
 * 		2014-08-15		create the file
 */

/**
 *	init alarm
 */
function init_alarm()
{
    _create_alarm_linkage();
    _create_alarm_record();
}

/**
 *	create alarm linkage store
 */
var g_alarm_linkage;
function _create_alarm_linkage()
{
    Ext.define
    ( "model_alarm_linkage", {
         extend:"Ext.data.Model",
         fields:[
             {name:"serial",			type:"int"},
             {name:"host",				type:"string"},
             {name:"dev_id",			type:"string"},
             {name:"cmp_start",			type:"string"}, // ">", "<", ">=", "<=", "==", "!="
             {name:"alm_start",			type:"string"},
             {name:"cmp_stop",			type:"string"}, // ">", "<", ">=", "<=", "==", "!="
             {name:"alm_stop",			type:"string"},
             {name:"link_host",			type:"string"},
             {name:"link_dev",			type:"string"},
         ],
         proxy:"memory"
    });

    g_alarm_linkage = new Ext.data.ArrayStore
    ({
         autoLoad:true,
         model:"model_alarm_linkage",
         /*
         data:[
             [0, "I/O通道", "tunnel5", "dev_el_0", "湿度传感器", ">", "78", "<", "30", "30度"],
             [1, "I/O通道", "tunnel5", "dev_el_1", "湿度传感器", ">", "66", "<", "20", "20%"],
             [2, "I/O通道", "tunnel5", "dev_el_1", "湿度传感器", "", "", "", "", ""],
         ]
         */
    });
}

/**
 *	create alarm record store
 */
var g_alarm_record;
function _create_alarm_record()
{
    Ext.define
    ( "model_alarm_record", {
         extend:"Ext.data.Model",
         fields:[
             {name:"host",				type:"string"},
             {name:"dev_id",			type:"string"},
             {name:"datetime",			type:"string"},
             {name:"value",				type:"string"}
         ],
         proxy:"memory"
    });

    g_alarm_record = Ext.create
    ("Ext.data.ArrayStore", {
         autoLoad:true,
         model:"model_alarm_record",
         data:[
             ["host", "dev_el_0", "2014-05-06 19:04:09", "56" ],
             ["host", "dev_el_0", "2014-07-08 11:14:03", "53" ],
             ["host", "dev_el_0", "2014-08 10 09:08:29", "48" ],
             ["host", "dev_el_0", "2014-08-16 17:36:51", "50" ]
         ]
    });
}

/**
 *	callback for setting alarm
 */
function callback_set_alarm( serial, host, dev_id, cmp_start, alm_start, cmp_stop, alm_stop, link_host, link_dev )
{
    var index			= g_alarm_linkage.count();
    var	device			= g_device.findRecord( "dev_id", dev_id );

    g_alarm_linkage.insert( index, [[serial, host, dev_id, cmp_start, alm_start, cmp_stop, alm_stop, link_host, link_dev]] );
}
